home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / wb-tools / toolmanager / tm_tools / insertkey.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-06  |  1.8 KB  |  84 lines

  1. ;/* InsertKey - compiles with SAS/C 5.10a by executing this file
  2. lc -cfis -v -b0 -iinclude:intui.sym -iinclude:pragmas.sym -M -O -j73 InsertKey
  3. blink InsertKey.o to InsertKey
  4. quit ;*/
  5. /*
  6. *    InsertKey
  7. *
  8. *    Inserts an input event corresponding to the (commodities-style)
  9. *    description of a keystroke give on the command line.
  10. *
  11. *    So e.g. 'InsertKey lcommand esc' would give you a shell on many
  12. *    systems.
  13. *
  14. *    Martin W. Scott, Sunday 01-Nov-92.
  15. */
  16. #include <exec/types.h>
  17. #include <dos/dos.h>
  18. #include <dos/rdargs.h>
  19. #include <libraries/commodities.h>
  20. #include <proto/exec.h>        /* use PRAGMAS */
  21. #include <proto/dos.h>
  22. #include <proto/commodities.h>
  23. #include <clib/alib_protos.h>
  24. void FreeIEvents(struct InputEvent *);
  25.  
  26. #define PROJECT    "InsertKey"    /* program name */
  27. #define ARGSTR    "KEY/A/F"    /* argument template */
  28. #define NARGS    1    /* number of args in template */
  29. #define KEY    0
  30.  
  31. LONG    main(void);        /* prototypes */
  32.  
  33. const char version_str[] = "$VER: InsertKey 1.0";
  34. struct DosLibrary *DOSBase;
  35. struct Library *CxBase;
  36.  
  37. BOOL InsertKey(char *);
  38.  
  39. LONG main(void)        /* entry: InsertKey */
  40. {
  41.     struct RDArgs *readargs;
  42.     LONG rargs[NARGS];
  43.     LONG rc = 20;
  44.  
  45.     if (DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37L))
  46.     {
  47.         if (readargs = ReadArgs(ARGSTR, rargs, NULL))
  48.         {
  49.             if (InsertKey((char *)rargs[KEY]))
  50.                 rc = 0;
  51.             else PutStr(PROJECT": Invalid string\n");
  52.         }
  53.         else PrintFault(IoErr(), PROJECT);
  54.  
  55.         CloseLibrary(DOSBase);
  56.     }
  57.  
  58.     return rc;
  59.  
  60. } /* main */
  61.  
  62. struct InputEvent ie;
  63.  
  64. BOOL
  65. InsertKey(char *str)
  66. {
  67.     IX ix;
  68.     BOOL success = FALSE;
  69.  
  70.     if (CxBase = OpenLibrary("commodities.library", 37L))
  71.     {
  72.         if (!ParseIX(str, &ix))
  73.         {
  74.             ie.ie_Class = ix.ix_Class;
  75.             ie.ie_Code = ix.ix_Code;
  76.             ie.ie_Qualifier = ix.ix_Qualifier;
  77.             AddIEvents(&ie);
  78.             success = TRUE;
  79.         }
  80.     }
  81.  
  82.     return success;
  83. }
  84.